<?php

class WorkerCaroselController extends Controller
{
    /*
     * 获取轮播图列表
     *
     */
	public function actionGetCaroselList()
	{

        try
        {
            //参数验证

            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //获取轮播图列表
            $searchsql= Util::initSearchSql();

            //排序
            $searchsql = $searchsql." order by priority  asc";
            //获取list
            $list = WorkerCarousel::model()->findAll($searchsql);


            //返回数据
            Util::responseList(count($list),$list);


        }catch (Exception $e)
        {
            Util::responseErrorMsg($e->getMessage());

        }
	}

    /*
     * 添加轮播图
     */
    public function actionAddCarosel()
    {

        try
        {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $link_url = Util::getParamNotEmpty("link_url");
            $title = Util::getParamNotEmpty("title");
            $pic_url = Util::getParamNotEmpty("pic_url");


            //添加录播图
            $obj = new WorkerCarousel();
            Util::initObjData($obj);

            $obj->link_url = $link_url;
            $obj->pic_url = $pic_url;
            $obj->title = $title;

            Util::saveObjData($obj);



            //返回数据
            Util::responseMsg(MsgConst::RETURN_SUCCESS);


        }catch (Exception $e)
        {
            Util::responseErrorMsg($e->getMessage());

        }
    }


    /*
     * 删除轮播图
     */
    public function actionDeleteCarosel()
    {

        try
        {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $pic_id = Util::getParamNotEmpty("pic_id");



            //删除录播图
            $obj = WorkerCarousel::model()->findByPK($pic_id);

            Util::checkExistAndNotDelete($obj);

            Util::deleteObjData($obj);

            Util::saveObjData($obj);



            //返回数据
            Util::responseMsg(MsgConst::RETURN_SUCCESS);


        }catch (Exception $e)
        {
            Util::responseErrorMsg($e->getMessage());

        }
    }


    //修改轮播图信息
    public function actionUpdateCarosel()
    {

        try
        {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $pic_id = Util::getParamNotEmpty("pic_id");
            $link_url = Util::getParamNotEmpty("link_url");
            $title = Util::getParamNotEmpty("title");
            $pic_url = Util::getParamNotEmpty("pic_url");



            //修改轮播图
            $obj = WorkerCarousel::model()->findByPK($pic_id);

            Util::checkExistAndNotDelete($obj);


            $obj->link_url = $link_url;
            $obj->pic_url = $pic_url;
            $obj->title = $title;

            Util::updateObjData($obj);

            Util::saveObjData($obj);



            //返回数据
            Util::responseMsg(MsgConst::RETURN_SUCCESS);


        }catch (Exception $e)
        {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
    * 获取列表
    *
    */
    public function actionPush()
    {
        try {
            //参数验证

            //检测

            //$sdk = new PushSDK();

            $key = 'people';
            $value = json_encode(array('name'=>'ball', 'age'=>'male'));

            $memcache = new Memcache();
            $memcache->connect('127.0.0.1', 11211);
            $memcache->set('key', 'Memcache test successful!', 0, 60);
            $result = $memcache->get('key');

            Yii::app()->memcache->set("1","2","3");




            //返回数据
               Util::responseMsg("12312");


            } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }






}